<template>
  <div class="sticky" :class="{ scrolling: isScroll, 'bg-black': showMenu }">
    <div class="brxe-container">
      <nav class="brxe-nav-nested">
        <!-- logo -->
        <NuxtLink to="/" class="brxe-logo">
          <logoSvg></logoSvg>
        </NuxtLink>

        <ul class="brxe-block justify-end gap-6 lg:justify-between lg:gap-0">
          <li v-for="(item, index) in navList" :key="index" class="menu-first-item" :class="getClassList(index)">
            <div class="brxe-dropdomw">
              <span>{{ item.title }}</span>
              <div class="down-icon" v-if="item.style">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" fill="none">
                  <path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path>
                </svg>
              </div>
            </div>

            <!-- 二级菜单 -->
            <style1 v-if="item.style === 1"></style1>
            <style2 v-if="item.style === 2"></style2>
          </li>
        </ul>

        <a href="#" class="download-app"> Launch App </a>

        <!-- 移动端菜单 -->
        <div class="z-10 block cursor-pointer text-4xl text-white sm:hidden">
          <menuIconSvg v-show="!showMenu" @click="onOpenMenu"></menuIconSvg>
          <closeIconSvg v-show="showMenu" @click="onOpenMenu"></closeIconSvg>
        </div>
      </nav>
    </div>
  </div>
  <mobileMenu v-if="showMenu"></mobileMenu>
</template>

<script setup lang="ts">
import style1 from './style-1.vue'
import style2 from './style-2.vue'

import menuIconSvg from '~/assets/images/svg/menu-icon-svg.vue'
import mobileMenu from '~/components/mobile-menu/index.vue'
import closeIconSvg from '~/assets/images/svg/close-icon-svg.vue'
import logoSvg from '~/assets/images/svg/leonardo-logo-white-svg.vue'

const showMenu = ref(false)

const navList = ref([
  {
    title: 'Features',
    style: 1
  },
  {
    title: 'Solutions',
    style: 2
  },
  {
    title: 'Resources',
    style: 3
  },
  {
    title: 'For Teams'
  },
  {
    title: 'For Developers'
  },
  {
    title: 'Contact'
  }
])

const isScroll = ref(false)

const scrollHandle = () => {
  isScroll.value = window.scrollY > 0
}

const onOpenMenu = () => {
  showMenu.value = !showMenu.value
}

const getClassList = (index: number) => {
  let c = ['hidden']

  if (index < 3) {
    c.push('md:block')
  }

  if (index > 3) {
    c.push('lg:block')
  }

  return c.join(' ')
}
onMounted(() => {
  window.addEventListener('scroll', scrollHandle)
})

onBeforeUnmount(() => {
  window.removeEventListener('scroll', scrollHandle)
})
</script>

<style lang="scss" scoped>
.sticky {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 78px;

  border-bottom: 1px solid transparent;
  transition: all 0.1s ease-in;
  background-position: 50%;
  background-size: cover;
  z-index: 20;

  display: flex;
  // justify-content: flex-start;
  align-items: center;

  &::before {
    position: absolute;
    content: '';
    width: 100%;
    height: 100%;
    left: 0;
    backdrop-filter: blur(44px);
    transition: opacity 0.1s ease-in;
  }
}

.scrolling {
  background: rgba(2, 3, 5, 0.75);
  border-bottom: 1px solid #282c42;
}

.brxe-container {
  max-width: 1180px;
  width: 100%;
  padding: 15px 20px;
  margin-left: auto;
  margin-right: auto;
}

.brxe-nav-nested {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: clamp(1.5rem, -0.80358rem + 15.3846vw, 3.5rem);
}

.brxe-logo {
  width: 175px;
  z-index: 1001;
  flex-shrink: 0;
}

.brxe-block {
  display: flex;
  font-weight: 500;
  width: 100%;
  color: #fff;
  transition: all 0.2s ease;

  .brxe-dropdomw {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 400;
    font-size: 14px;
    cursor: pointer;

    .down-icon {
      width: 14px;
      height: 14px;
    }

    svg {
      stroke: #fff;
    }
  }
}

.menu-first-item {
  position: relative;

  &:hover {
    .second-list-wrapper {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
    }
  }
}

.download-app {
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
  border-radius: 60px;
  box-shadow:
    0 0 2px rgb(255 255 255 / 0.7) inset,
    0px 0px 15px 0px rgb(0 0 0 / 0%);
  background: linear-gradient(175deg, rgba(255, 255, 255, 0.35) -94.09%, rgba(255, 255, 255, 0) 154.53%);
  backdrop-filter: blur(21px);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 20px;
  color: #fff;
  flex-shrink: 0;
  width: auto;
}

// 菜单居中 - 主要是 pad 屏幕
@media screen and (max-width: 1024px) {
  .menu-first-item {
    &:hover {
      .second-list-wrapper {
        transform: translate(-50%, 0);
      }
    }
  }
}

@media screen and (max-width: 375px) {
  .download-app {
    font-size: 14px;
    padding: 6px 8px;
  }

  .brxe-logo {
    width: 120px;
    // height: 48px;
  }

  .brxe-nav-nested {
    gap: 10px;
  }
}
</style>
